package com.csx.governance.sample.serviceD.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author cuisongxu
 * @date 2023/4/2 18:35
 */
@RequestMapping("/serviceD")
@RestController
public class ServiceDController {

    @Autowired
    private Registration registration;

    /**
     * 这是测试包含消息的全链路的接口
     * @param request
     * @return
     */
    @GetMapping("/testFullLink")
    public String testFullLink(HttpServletRequest request) {
        System.out.println(request);
        String swimLane = request.getHeader("swimLane");
        System.out.println(swimLane);
        Map<String, String> metadata = registration.getMetadata();
        String host = registration.getHost();
        int port = registration.getPort();
        String instanceInfo = host + ":" + port + "  metadata: " + metadata.toString();
        return "serviceD " + instanceInfo + " ->  \n";
    }
}
